<?php
/* @var $this PurchaseOrderHeaderController */
/* @var $model PurchaseOrderHeader */

$this->breadcrumbs=array(
	'Purchase Order Headers'=>array('index'),
	'Create',
);

$this->menu=array(
	array('label'=>'List Purchase Order', 'url'=>array('index')),
);

Yii::app()->clientScript->registerScript('search', "
	$( document ).ready(function() {

	  var x= $('#quo_no').val();
	  $('#quotation_no').combogrid('setValue',x);
	  
	  if(x!='')
	  	$('#quotation_no').combogrid('disable');
	
	});

	$( '#submitBtn' ).click(function(){
		$('#quo_no').val( $('#quotation_no').combogrid('getValue'));
	});

	function addItem(){
        $(this).dialog('close');
        var tempQuoNo=$('#tempQuoNo').val();
        var customer=$('#customerPick').val();
        
        var matches = customer.match(/\b(\w)/g);
        var tempCustomer = matches.join('');

        tempQuoNo=tempQuoNo.replace('?',tempCustomer.toUpperCase());
        $('#quotation_no').val(tempQuoNo);
        $('#customer1').val(customer);
    }
");

?>
<h1>Create Purchase Order</h1>

<?php 
    if(isset($vendorLabel)){
        $currentIndex=Yii::app()->session['vendorList']+1;
        $sizeList=Yii::app()->session['sizeVendorList'];
    
        echo CHtml::label('Vendor '.$currentIndex.' of '.$sizeList, '',array(
        'class' => 'pull-right'
        ));
    } 
?>

<?php $this->renderPartial('_form', array('model'=>$model,'quo_no'=>$quo_no,'purNo'=>$purNo,'vendorLabel'=>$vendorLabel,'vendorId'=>$vendorId)); ?>


<?php
	/*$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id'=>'vendor_dialog',
        'options'=>array(
            'title'=>'Select Vendor',
            'autoOpen'=>true,
            'modal'=>true,
			'width'=>520,
            'buttons'=>array(
                'Submit'=>'js:addItem',
                'Cancel'=>'js:function(){ $(this).dialog("close");}',
            ),
        ),
    ));
	
    echo '<table width="380px">
            <tr>
                <td>';
                $this->widget('ext.combobox.EJuiComboBox', array(
                    'model' => $model,
                    'attribute' => 'datePO',//nanti diubah
                    //'data' => CHtml::listData(Vendor::model()->with('products','products.vendorID','products.productPn')->findAll(),'id','vendor'),
                    'data' => CHtml::listData(Vendor::model()->with('products','products.quotationDetail')->findAll('id=vendor_id and products.product_pn=quotationDetail.product_pn and quotation_no=:quotation_no',array('quotation_no'=>$quo_no)),'id','vendor'),
                    'options' => array(
                       'allowText' => false,
                    ),
                    'htmlOptions' => array('size' => 10),
                ));
    /*echo'            </td>
                <td width="70%"><input type="hidden" id="tempQuoNo" value="'.$this->getQuoNo().'"/></td>
                <td width="30%">';
                DialogBox::createDialogBox(
					 $this
					,"addCustomer"
					,"Type new customer:"
					,"quotationOrderHeader/customer"
					,"customerPick"
					,"sampleIconCssStyle"
					,400,250
				); */
    /*echo '      </td>
            </tr>
          </table>
        ';
    $this->endWidget('zii.widgets.jui.CJuiDialog');*/

    ?>
    